﻿<!--2025-6-4 胡莹 创作-->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>兔子繁殖树形游戏</title>
    <style>
        body {
            font-family: 'Comic Sans MS', cursive, sans-serif;
            background-color: #f9f3e9;
            margin: 0;
            padding: 20px;
            text-align: center;
        }
        .game-container {
            max-width: 1000px;
            margin: 0 auto;
            background-color: #fff9f0;
            border-radius: 20px;
            padding: 20px;
            box-shadow: 0 0 20px rgba(0,0,0,0.1);
        }
        h1 {
            color: #e67e7e;
            text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
        }
        .setup-btn {
            background-color: #e67e7e;
            color: white;
            border: none;
            padding: 15px 30px;
            font-size: 20px;
            border-radius: 50px;
            cursor: pointer;
            margin: 20px 0;
            transition: all 0.3s;
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
        }
        .check-btn, .reset-btn {
            color: white;
            border: none;
            padding: 12px 25px;
            font-size: 18px;
            border-radius: 50px;
            cursor: pointer;
            transition: all 0.3s;
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
        }

        .setup-btn:hover {
            background-color: #d46a6a;
            transform: translateY(-3px);
            box-shadow: 0 6px 12px rgba(0,0,0,0.15);
        }
        .tree-container {
            display: flex;
            flex-direction: column;
            align-items: center;
            margin: 30px 0;
            min-height: 400px;
        }
        .generation {
            display: flex;
            justify-content: center;
            margin: 20px 0;
            position: relative;
            min-width: 80%;
        }
        .generation::before {
            content: "";
            position: absolute;
            top: -20px;
            width: 80%;
            height: 3px;
            background-color: #d4b483;
            border-radius: 3px;
        }
        .month-label {
            position: absolute;
            top: -50px;
            left: 50%;
            transform: translateX(-50%);
            background-color: #e67e7e;
            color: white;
            padding: 8px 16px;
            border-radius: 30px;
            font-weight: bold;
            box-shadow: 0 2px 5px rgba(0,0,0,0.2);
            z-index: 10;
        }
        .rabbit-pair {
            display: flex;
            flex-direction: column;
            align-items: center;
            margin: 0 25px;
            position: relative;
            transition: all 0.3s;
        }
        .rabbit-pair:hover {
            transform: translateY(-5px);
        }
        .rabbit-pair::after {
            content: "";
            position: absolute;
            top: -20px;
            width: 3px;
            height: 20px;
            background-color: #d4b483;
        }
        .rabbit {
            width: 80px;
            height: 80px;
            margin: 8px;
            cursor: move;
            transition: all 0.2s;
            object-fit: contain;
        }
        .rabbit:hover {
            transform: scale(1.15);
            filter: drop-shadow(0 5px 5px rgba(0,0,0,0.2));
        }
        .big-rabbit {
            border: 3px solid #b58a5a;
            border-radius: 50%;
            background-color: #f5d7b3;
            padding: 5px;
        }
        .small-rabbit {
            border: 3px solid #a8c3d0;
            border-radius: 50%;
            background-color: #e6f2f7;
            padding: 5px;
        }
        .controls {
            margin: 30px 0;
        }
        .check-btn {
            background-color: #7eb8e6;
            color: white;
            border: none;
            padding: 12px 25px;
            font-size: 18px;
            border-radius: 50px;
            cursor: pointer;
            transition: all 0.3s;
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
        }
        .check-btn:hover {
            background-color: #6ca8d4;
            transform: translateY(-3px);
            box-shadow: 0 6px 12px rgba(0,0,0,0.15);
        }
        .check-btn:disabled {
            background-color: #cccccc;
            cursor: not-allowed;
            transform: none;
            box-shadow: none;
        }
        .rabbit-pool {
            display: flex;
            justify-content: center;
            margin: 30px 0;
            gap: 40px;
            flex-wrap: wrap;
        }
        .rabbit-source {
            display: flex;
            flex-direction: column;
            align-items: center;
        }
        .rabbit-label {
            margin-top: 10px;
            font-weight: bold;
            color: #666;
        }
        .instructions {
            background-color: #f0e6d2;
            padding: 20px;
            border-radius: 15px;
            margin: 25px 0;
            text-align: left;
            border-left: 6px solid #e67e7e;
            box-shadow: inset 0 0 10px rgba(0,0,0,0.05);
        }
        .highlight {
            color: #e67e7e;
            font-weight: bold;
            background-color: #f9e9e9;
            padding: 2px 6px;
            border-radius: 4px;
        }
        .stats {
            background-color: #f5e7d7;
            padding: 15px;
            border-radius: 15px;
            margin: 20px auto;
            display: inline-block;
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
            font-size: 18px;
        }
        .stat-item {
            margin: 0 15px;
            display: inline-block;
        }
        .stat-value {
            font-weight: bold;
            color: #e67e7e;
        }
        .connector {
            position: absolute;
            top: -20px;
            width: 3px;
            height: 20px;
            background-color: #d4b483;
            left: 50%;
            transform: translateX(-50%);
        }
        .ground {
            width: 100%;
            height: 20px;
            background-color: #d4b483;
            border-radius: 0 0 15px 15px;
            margin-top: 20px;
        }
        .feedback {
            margin: 20px 0;
            padding: 15px;
            border-radius: 10px;
            font-weight: bold;
            display: none;
        }
        .correct {
            background-color: #d4edda;
            color: #155724;
            border: 2px solid #c3e6cb;
        }
        .incorrect {
            background-color: #f8d7da;
            color: #721c24;
            border: 2px solid #f5c6cb;
        }
        .month-stats {
            font-size: 14px;
            margin-top: 10px;
            color: #666;
        }
    </style>
</head>
<body>
    <div class="game-container">
        <h1>🐇 斐波那契数列探秘小游戏 🌳</h1>
               
        
        <button class="setup-btn" onclick="setupGame()">🎮 开始游戏</button>
             <button class="reset-btn" id="resetBtn" onclick="resetGame()">🔄 重置游戏</button>
        
        <div class="rabbit-pool" id="rabbitPool" style="display:none;">
            <div class="rabbit-source">
                <img src="tumama.jpg" 
                     class="rabbit big-rabbit" 
                     draggable="true" 
                     alt="大兔子" 
                     title="拖动大兔子">
                <div class="rabbit-label">大兔子</div>
            </div>
            <div class="rabbit-source">
                <img src="xiaotu.jpg" 
                     class="rabbit small-rabbit" 
                     draggable="true" 
                     alt="小兔子" 
                     title="拖动小兔子">
                <div class="rabbit-label">小兔子</div>
            </div>
        </div>
        
        <div class="stats" id="stats" style="display:none;">
            <div class="stat-item">当前月份: <span class="stat-value" id="current-month">1</span></div>
            <div class="stat-item">你的答案: <span class="stat-value" id="user-answer">未检查</span></div>
        </div>
        
        <div class="feedback" id="feedback"></div>
        
        <div class="controls" style="display:none;">
            <button class="check-btn" id="checkBtn" onclick="checkAnswer()">✅ 检查答案</button>
        </div>
        
        <div class="tree-container" id="treeContainer">
            <!-- 树形结构会在这里动态生成 -->
        </div>
        
        <div class="ground"></div>
    </div>

    <script>
        // 正确的斐波那契兔子数量 (月份1-6)
        const correctCounts = [
            { month: 1, small: 1, big: 0, total: 1 },
            { month: 2, small: 0, big: 1, total: 1 },
            { month: 3, small: 1, big: 1, total: 2 },
            { month: 4, small: 1, big: 2, total: 3 },
            { month: 5, small: 2, big: 3, total: 5 },
            
        ];
        
        let userRabbitCounts = [];
        let rabbitPairs = [];
        const maxMonths = 5;
        
        // 大兔子和小兔子图片
        const bigRabbitImg = "tumama.jpg";
        const smallRabbitImg = "xiaotu.jpg";
        
        function setupGame() {
            document.querySelector('.setup-btn').style.display = 'none';
            document.getElementById('rabbitPool').style.display = 'flex';
            document.querySelector('.controls').style.display = 'block';
            document.getElementById('stats').style.display = 'block';
            
            // 初始化用户兔子数量
            userRabbitCounts = Array(maxMonths).fill().map((_, i) => ({
                month: i + 1,
                small: 0,
                big: 0,
                total: 0
            }));
            
            // 创建6个月的树形结构框架
            renderEmptyTree();
            setupDragAndDrop();
        }
        
        function renderEmptyTree() {
            const container = document.getElementById('treeContainer');
            container.innerHTML = '';
            
            for (let month = 1; month <= maxMonths; month++) {
                const generation = document.createElement('div');
                generation.className = 'generation';
                generation.id = `generation-${month}`;
                
                const label = document.createElement('div');
                label.className = 'month-label';
                label.textContent = `第 ${month} 个月`;
                generation.appendChild(label);
                
                // 空的兔子区域，等待用户拖动
                const dropZone = document.createElement('div');
                dropZone.className = 'rabbit-drop-zone';
                dropZone.dataset.month = month;
                dropZone.style.minHeight = '100px';
                dropZone.style.minWidth = '200px';
                generation.appendChild(dropZone);
                
                container.appendChild(generation);
            }
        }
        
        function setupDragAndDrop() {
            // 设置兔子图片的拖拽
            const rabbits = document.querySelectorAll('.rabbit');
            
            rabbits.forEach(rabbit => {
                rabbit.addEventListener('dragstart', function(e) {
                    e.dataTransfer.setData('type', this.classList.contains('big-rabbit') ? 'big' : 'small');
                    e.dataTransfer.setData('src', this.src);
                    e.dataTransfer.effectAllowed = 'copy';
                });
            });
            
            // 设置树形区域的放置
            const generations = document.querySelectorAll('.generation');
            
            generations.forEach(gen => {
                gen.addEventListener('dragover', function(e) {
                    e.preventDefault();
                    e.dataTransfer.dropEffect = 'copy';
                    this.style.backgroundColor = '#f0f0f0';
                });
                
                gen.addEventListener('dragleave', function() {
                    this.style.backgroundColor = '';
                });
                
                gen.addEventListener('drop', function(e) {
                    e.preventDefault();
                    this.style.backgroundColor = '';
                    
                    const rabbitType = e.dataTransfer.getData('type');
                    const rabbitSrc = e.dataTransfer.getData('src');
                    const month = parseInt(this.id.split('-')[1]);
                    
                    // 创建新的兔子图片
                    const rabbitImg = document.createElement('img');
                    rabbitImg.src = rabbitSrc;
                    rabbitImg.className = `rabbit ${rabbitType}-rabbit`;
                    rabbitImg.draggable = true;
                    rabbitImg.dataset.type = rabbitType;
                    
                    // 添加到当前月份
                    this.appendChild(rabbitImg);
                    
                    // 更新用户兔子数量
                    if (rabbitType === 'big') {
                        userRabbitCounts[month-1].big++;
                    } else {
                        userRabbitCounts[month-1].small++;
                    }
                    userRabbitCounts[month-1].total = userRabbitCounts[month-1].small + userRabbitCounts[month-1].big;
                    
                    // 更新当前月份显示
                    document.getElementById('current-month').textContent = month;
                });
            });
        }
        
        function checkAnswer() {
            let allCorrect = true;
            let feedbackMessage = "";
            
            // 检查每个月份的数量
            for (let month = 1; month <= maxMonths; month++) {
                const correct = correctCounts[month-1];
                const user = userRabbitCounts[month-1];
                
                if (user.small !== correct.small || user.big !== correct.big) {
                    allCorrect = false;
                    feedbackMessage += `第 ${month} 个月: 应该是 小兔子 ${correct.small} 对, 大兔子 ${correct.big} 对<br>`;
                }
            }
            
            const feedbackDiv = document.getElementById('feedback');
            
            if (allCorrect) {
                feedbackDiv.className = "feedback correct";
                feedbackDiv.innerHTML = "🎉 恭喜！所有月份的兔子数量都正确！<br><br>";
                
                // 显示每个月的正确数量
                feedbackDiv.innerHTML += "<strong>正确的兔子数量:</strong><br>";
                correctCounts.forEach(month => {
                    feedbackDiv.innerHTML += `第 ${month.month} 个月: 小兔子 ${month.small} 对, 大兔子 ${month.big} 对, 总数 ${month.total} 对<br>`;
                });
                
                document.getElementById('user-answer').textContent = "完全正确";
            } else {
                feedbackDiv.className = "feedback incorrect";
                feedbackDiv.innerHTML = "😅 还有一些月份不正确:<br><br>" + feedbackMessage;
                
                document.getElementById('user-answer').textContent = "部分正确";
            }
            
            feedbackDiv.style.display = "block";
            
            // 显示每个月的统计
            const monthStats = document.createElement('div');
            monthStats.className = 'month-stats';
            monthStats.innerHTML = "<strong>你的答案统计:</strong><br>";
            
            userRabbitCounts.forEach(month => {
                monthStats.innerHTML += `第 ${month.month} 个月: 小兔子 ${month.small} 对, 大兔子 ${month.big} 对, 总数 ${month.total} 对<br>`;
            });
            
            feedbackDiv.appendChild(monthStats);
        }
function resetGame() {
            // 清空树形结构
            document.getElementById('treeContainer').innerHTML = '';
            
            // 重置用户兔子数量
            userRabbitCounts = Array(maxMonths).fill().map((_, i) => ({
                month: i + 1,
                small: 0,
                big: 0,
                total: 0
            }));
            
            // 重置UI状态
            document.getElementById('feedback').style.display = 'none';
            document.getElementById('user-answer').textContent = "未检查";
            document.getElementById('current-month').textContent = "1";
            
            // 重新设置游戏
            setupGame();
        }

    </script>
</body>
</html>